from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

# url=input('请输入https://网址')
# 选项
options = webdriver.ChromeOptions()
# 第一次打开的，加入端口
# options.add_argument("--remote-debugging-port=9222")
# 之后打开的，加入实验选项
# chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")#【name 'chrome_options' is not defined
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
# 路径
options.binary_location = r"G:\PC Package\Chrome\App\Chrome.exe"#[win8]
chrome_driver_path = r"G:\PC Package\Chrome\App\chromedriver.exe"
'''
# 路径win10
options.binary_location = r"D:\PC Package\Chrome 97.0.4692.71\App\Chrome.exe"win10
chrome_driver_path = r"D:\PC Package\Chrome 97.0.4692.71\App\chromedriver.exe"
# s=Service(r'D:\PC Package\Chrome\App\chromedriver.exe')
'''
# 服务
chrome_driver_path_obj = Service(chrome_driver_path)

# 第一次打开的，
# driver = webdriver.Chrome(executable_path=chrome_driver_path,service=chrome_driver_path_obj,options=options)#成功 executable_path has been deprecated, please pass in a Service object
# 之后打开的
# driver = webdriver.Chrome(options=chrome_options)
driver = webdriver.Chrome(service=chrome_driver_path_obj,options=options)#成功
driver = webdriver.Chrome(options=options)#成功

time.sleep(2)
# url='https://www.baidu.com'
url='https://www.sogou.com'
driver.get(url)

driver.close()